package com.ezandroid.library.image.ext.core.display;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;

import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;

/**
 * Created by MaXingliang on 2014/8/28.
 */
public class CircleRingBitmapDisplayer extends CircleBitmapDisplayer {

    private static final int RING_WIDTH = 2;

    @Override
    public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
        imageAware.setImageDrawable(new CircleRingDrawable(bitmap));
    }

    public static class CircleRingDrawable extends CircleDrawable {

        public CircleRingDrawable(Bitmap bitmap) {
            super(bitmap);
        }

        @Override
        public void draw(Canvas canvas) {
            int ringMargin = RING_WIDTH / 2;

            RectF rectRing = new RectF(mRect.left + ringMargin, mRect.top + ringMargin, mRect.right
                    - ringMargin, mRect.bottom - ringMargin);
            Paint paint1 = new Paint();
            paint1.setAntiAlias(true);
            paint1.setColor(Color.WHITE);
            paint1.setStyle(Paint.Style.STROKE);
            paint1.setStrokeWidth(RING_WIDTH);
            canvas.drawOval(rectRing, paint1);

            canvas.drawCircle(mRect.width() / 2, mRect.height() / 2,
                    mRect.width() / 2 - RING_WIDTH, paint);
        }
    }
}
